package Volume1.ch10;

import javax.swing.*;
import java.awt.*;

/**
 * @Auther jacob
 * @Date 2020/8/16 00:24
 */
public class SizedFrameTest {
    public static void main(String[] args) {
        EventQueue.invokeLater(()->{
            SizedFrame sizedFrame = new SizedFrame();
            sizedFrame.setTitle("Tom");
            sizedFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            sizedFrame.setVisible(true);
        });
    }

}

class SizedFrame extends JFrame{

    // 构造函数中初始化Frame属性
    public SizedFrame(){
        // 获取屏幕相关尺寸信息
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();
        int height = screenSize.height;
        int width = screenSize.width;

        // 设置frame的高和宽，并告知窗口系统定位框架
        setSize(width/2, height/2);
        setLocationByPlatform(true);

        // 设置frame的图片
        Image image = new ImageIcon("src/source/tom.png").getImage();
        setIconImage(image);


    }
}
